package dao;

import common.Course;
import common.Select;
import common.Topic;
import common.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class GetTeach {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="select id,name,teacherId,teacherName,code,description from course where teacherId=?";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static Vector<Course> getTeach(String teacherId){
        Vector<Course> courses=new Vector<>();
        try {
            pstmt.setString(1,teacherId);
            ResultSet rs=pstmt.executeQuery();
            while (rs.next()){
                Vector<User> student=GetStu.gatStu(rs.getString(1));
                Vector<Select> selectTask=GetSelectTask.gatSelectTask(rs.getString(1));
                Vector<Topic> topics=GetTopic.getTopic(rs.getString(1),student);
                Course add=new Course(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),student);
                add.setSelectTask(selectTask);
                add.setTopicTask(topics);
                courses.add(add);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("获取我教的课失败");
        }
        return courses;
    }
}
